Passed
Push — master ( e1d21b...121756 )
by Anthony
02:12
created

$(document).ready   B

Complexity

Conditions 1
Paths 32

Size

Total Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
nc 32
nop 0
dl 0
loc 80
rs 8.8387
c 1
b 0
f 1

7 Functions

Rating   Name   Duplication   Size   Complexity  
C 0 25 8
A 0 4 1
A 0 5 1
B 0 20 5
A 0 5 1
A 0 5 3
A 0 5 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
$(document).ready(function() {
2
	function ValidateDate(dtValue)  {
3
		var dtRegex = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/);
4
		return dtRegex.test(dtValue);
5
	}
6
7
	//---------------------------- EFFECT MATERIAL ON INPUT INPUT -----------------------------//
8
	$('.block input').focus(function() {
9
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
10
		$parent.addClass('is-focused has-label');
11
		$parent.removeClass('invalid');
12
	});
13
14
	$('.block input').blur(function() {
15
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
16
		$this = $(this);
0 ignored issues
show
Bug introduced by
The variable $this seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$this.
Loading history...
17
18
        var type = $this.attr("type-val");
19
        var min = $this.attr("min");
20
        var max = $this.attr("max");
21
22
        if (type == "string") {
23
            if ($this.val() == "") {
24
                $parent.addClass('invalid');
25
                $parent.removeClass('has-label');
26
            }
27
            else if (($this.val().length < min) || ($this.val().length > max)) {
28
                $parent.addClass('invalid');
29
            }
30
        }
31
        else if (type == "date") {
32
            if (($this.attr('name') == "date") && (!ValidateDate($this.val()))) {
33
                $parent.addClass('invalid');
34
            }
35
        }
36
37
		$parent.removeClass('is-focused');
38
	});
39
40
	$('.block input').each(function() {
41
		if (($(this).val() != '') || ($(this).val() != 0)) {
42
			$(this).parent().addClass('has-label');
43
		}
44
	});
45
46
47
	$('.block textarea').focus(function() {
48
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
49
		$parent.addClass('is-focused has-label');
50
		$parent.removeClass('invalid');
51
	});
52
53
	$('.block textarea').blur(function() {
54
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
55
		$this = $(this);
0 ignored issues
show
Bug introduced by
The variable $this seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$this.
Loading history...
56
57
        var type = $this.attr("type-val");
58
        var min = $this.attr("min");
59
        var max = $this.attr("max");
60
61
        if (type == "string") {
62
            if ($this.val() == "") {
63
                $parent.addClass('invalid');
64
                $parent.removeClass('has-label');
65
            }
66
            else if (($this.val().length < min) || ($this.val().length > max)) {
67
                $parent.addClass('invalid');
68
            }
69
        }
70
71
		$parent.removeClass('is-focused');
72
	});
73
74
	$('.block textarea').each(function() {
75
		if (($(this).val() != '') || ($(this).val() != 0)) {
76
			$(this).parent().addClass('has-label');
77
		}
78
	});
79
    //---------------------------- END EFFECT MATERIAL ON INPUT INPUT -----------------------------//
80
})